package sostats.core.query;

import java.util.List;

import com.google.common.base.Joiner;

public class Having extends Clause{
	private List<String> andConditions;
	private List<String> orConditions;
	public Having(SqlContext context) {
		super(context,"HAVING");
	}
	public Having or(String condition){
		orConditions.add(condition);
		return this;
	}
	public Having and(String condition){
		andConditions.add(condition);
		return this;
	}
	@Override
	void endClause() {
		String and = Joiner.on(" and ").join(andConditions);
		String or = Joiner.on(" or ").join(orConditions);
		if(and.length()==0){
			context.append(or);
		}else if(or.length()==0){
			context.append(and);
		}else{
			context.append(and);
			context.append(" or ");
			context.append(or);
		}
	}
}
